import { ReactNode } from 'react'
import { ICellRendererParams } from '@ag-grid-community/core'

import { Texty } from '@/components/Texty'

export const addTexty = (showContent: ReactNode, tipContent?: ReactNode) => (
  <Texty content={tipContent || showContent}>{showContent}</Texty>
)

export const addAGCellTexty = (cellParams: ICellRendererParams) => {
  const { colDef, value, valueFormatted } = cellParams

  const text = valueFormatted ?? value ?? ''

  if (typeof text !== 'string' && typeof text !== 'number') return

  if (colDef?.autoHeight && colDef?.wrapText) {
    return text
  }

  return addTexty(text)
}
